﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Zgq.CommonTools
{
    public partial class LambdaToSqlExpression<T>
    {
        private C5DataBaseHelper dbConn = null;
        public LambdaToSqlExpression(C5DataBaseHelper _dbConn)
        {
            this.dbConn = _dbConn;
        }

        public T FirstOrDefault()
        {
            return this.dbConn.SelectModel<T>(GetWhereStr(), GetOrderByStr());
        }
        public List<T> ToList()
        {
            return this.dbConn.SelectList<T>(GetWhereStr(), GetOrderByStr());
        }
        public List<T> ToList(int pageIndex, int pageSize)
        {
            return this.dbConn.SelectListPaging<T>(pageIndex, pageSize, GetWhereStr(), GetOrderByStr());
        }
        public DataTable ToDataTable()
        {
            return this.dbConn.SelectDatatable(typeof(T).Name, GetWhereStr(), GetOrderByStr(), GetSelectStr());
        }
        public DataTable ToDataTable(int pageIndex, int pageSize)
        {
            return this.dbConn.SelectDatatablePaging(typeof(T).Name, pageIndex, pageSize, GetWhereStr(), GetOrderByStr(), GetSelectStr());
        }
    }
}
